package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.dto.User;
import com.example.demo.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhanpengguo
 * @date 2019-07-03 15:04
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequiresRoles("admin")
    @GetMapping("/show/{name}")
    public String showUser(@PathVariable("name") String name){
        User user = userService.findByName(name);
        return JSONObject.toJSONString(user);
    }

    @RequiresPermissions("delete")
    @PutMapping("/delete")
    public String delete(){
        return "修改成功";
    }
}
